package panels.util;

import java.awt.BorderLayout;
import java.awt.SystemColor;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JPanel;

public class FlagDisplay extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel leftPanel;
	private JPanel centerPanel;
	private JPanel rightPanel;

	public int getCenterLeft() {
		return getWidth()/4;
	}
	
	public int getCenterRight() {
		return getWidth()*3/4;
	}
	
	public int getCenter() {
		return getWidth()/2;
	}
	
	/**
	 * Create the panel.
	 */
	public FlagDisplay() {
		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				// Adjust the left panel
				getLeftPanel().setLocation(0,0);
				getLeftPanel().setSize(getCenterLeft(), getHeight());
				getLeftPanel().invalidate();
//				getLeftPanel().paintImmediately(getLeftPanel().getVisibleRect());

				// Adjust the right panel
				getRightPanel().setLocation(getCenterRight(),0);
				getRightPanel().setSize(getWidth()-getCenterRight(), getHeight());
				getRightPanel().invalidate();
//				getRightPanel().paintImmediately(getRightPanel().getVisibleRect());
				
				// Adjust the center panel
				getCenterPanel().setLocation(getCenterLeft(),0);
				getCenterPanel().setSize(getCenterRight()-getCenterLeft(), getHeight());
				getCenterPanel().invalidate();
//				getCenterPanel().paintImmediately(getCenterPanel().getVisibleRect());
		
				invalidate();
				paintImmediately(getVisibleRect());
			}
		});
		setLayout(null);
		
		
		leftPanel = new JPanel();
		leftPanel.setBackground(SystemColor.control);
		leftPanel.setBounds(205, 5, 10, 10);
		add(leftPanel);
		leftPanel.setLayout(new BorderLayout(0, 0));
		
		centerPanel = new JPanel();
		centerPanel.setBackground(SystemColor.control);
		centerPanel.setBounds(220, 5, 10, 10);
		add(centerPanel);
		centerPanel.setLayout(new BorderLayout(0, 0));
		
		rightPanel = new JPanel();
		rightPanel.setBackground(SystemColor.control);
		rightPanel.setBounds(235, 5, 10, 10);
		add(rightPanel);
		rightPanel.setLayout(new BorderLayout(0, 0));
	}

	public JPanel getLeftPanel() {
		return leftPanel;
	}
	public JPanel getCenterPanel() {
		return centerPanel;
	}
	public JPanel getRightPanel() {
		return rightPanel;
	}
}
